﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
using Ewts.Code;
using DataLib.Accounts.Bus;
namespace Ewts.RDLC
{
    public partial class LTRRDLC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //归属地
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                DataLib.BLL.City bllLib = new DataLib.BLL.City();
                dropBcity.DataSource = bllLib.GetList("flag1 = '01'");
                dropBcity.DataTextField = "cityname";
                dropBcity.DataValueField = "citycode";
                dropBcity.DataBind();
                dropBcity.Items.Insert(0, item);
                dropBcity.SelectedItem.Text = "";


                // 处理地
                ddlGraphic.DataSource = bllLib.GetList("flag1 = '01'");
                ddlGraphic.DataTextField = "cityname";
                ddlGraphic.DataValueField = "citycode";
                ddlGraphic.DataBind();
                ddlGraphic.Items.Insert(0, item);

                ddlGraphic.SelectedItem.Text = "";
           
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string loadnum = txtLoadnum.Text;
            string graphic = ddlGraphic.SelectedItem.Text;
             string goodsname = txtGoodsName.Text;
            string nwt = txtnwt.Text;
            string cum = txtCum.Text;
            string cumCode = txtcumCode.Text;
            string CADateInvice = txtCADateInvice.Text;
            string CEDate = txtCEDate.Text;
            string CollectDate = txtCollectDate.Text;
            string month = txtCollectMonth.Text;
            string tallydate = txtTallyDate.Text;
            string loaddate = txtloadDate.Text;
            string WRLdate = txtWRLdate.Text;
            string saleman = txtsaleman.Text.Trim();
            string shortname = txtShortName.Text.Trim();
            string remark = txtRemark.Text.Trim();
            string proname = txtPro.Text.Trim();
            string bcity = dropBcity.SelectedItem.Text;
            
            #region strwhere
            string strwhere = " 1=1 ";
            if (loadnum.Trim() != "") 
            {
                strwhere += " and loadnum='" + loadnum +"' ";
            }
            if (graphic != null && graphic.Trim() != "")
            {
                strwhere += " and cjocollcity='" + graphic + "' ";
            }
            if (goodsname != null && goodsname.Trim() != "")
            {
                strwhere += " and goodsinfo like '%" + goodsname + "%' ";
            }
            if (nwt != null && nwt.Trim() != "")
            {
                strwhere += " and nwt=" + nwt;
            }
            if (cumCode != null && cumCode.Trim() != "")
            {
                strwhere += " and customercode like '%" + cumCode + "%' ";
            }
            if (CADateInvice != null && CADateInvice.Trim() != "")
            {
                strwhere += " and CADate like '%" + CADateInvice + "%' ";
            }
            if (CEDate != null && CEDate.Trim() != "")
            {
                strwhere += " and CEDate like '%" + CEDate + "%' ";
            }
            if (CollectDate != null && CollectDate.Trim() != "")
            {
                strwhere += " and reservecolldate like '%" + CollectDate + "%' ";
            }
            if (month != null && month.Trim() != "")
            {
                strwhere += " and collmonth like '%" + month + "%' ";
            }
            if (tallydate != null && tallydate.Trim() != "")
            {
                strwhere += " and tallydate like '%" + tallydate + "%' ";
            }
            if (loaddate != null && loaddate.Trim() != "")
            {
                strwhere += " and loadcreatedate like '%" + loaddate + "%' ";
            }
            if (WRLdate != null && WRLdate.Trim() != "")
            {
                strwhere += " and wrldate like '%" + WRLdate + "%' ";
            }
            if (bcity != null && bcity.Trim() != "")
            {
                strwhere += " and projectcity like '%" + bcity + "%' ";
            }
            if (proname != null && proname.Trim() != "")
            {
                strwhere += " and projectname like '%" + proname + "%' ";
            }
            #endregion

            DataTable dt = new DataLib.BLL.LTR_CJO().GetList(strwhere).Tables[0];
            //if (dt!=null&&dt.Rows.Count>0)
            //{
            //    dt.Columns.Add("month");
            //    for (int i = 0; i < dt.Rows.Count; i++)
            //    {
            //        dt.Rows[i]["month"] = DateTime.Parse(dt.Rows[i]["lm_collectdate"].ToString()).Month;
            //    }
            //}
            List<ReportParameter> parameterList = new List<ReportParameter>();
            ReportDataSource rds = new ReportDataSource("ltrDs", dt);
            ltrReport.LocalReport.DataSources.Clear();
            ltrReport.LocalReport.DataSources.Add(rds);
            new RDLCPrinter().FillRow(dt, 3, 20, 20);
            ltrReport.LocalReport.SetParameters(parameterList);
            ltrReport.LocalReport.Refresh();
            clearAll();
        }

        protected void clearAll()
        {
            this.txtCADateInvice.Text = "";
            txtTallyDate.Text = "";
            txtWRLdate.Text = "";
            txtloadDate.Text = "";
            txtCollectDate.Text = "";
            txtCollectMonth.Text = "";
            txtCum.Text = "";
            txtcumCode.Text = "";
            txtCEDate.Text = "";
        }

    }
}